package com.jiezhuo.config;
import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration//配置类
@EnableSwagger2 //swagger注解
public class SwaggerConfig {
    @Value("${swagger.enable: true}")
    boolean enable;
    @Bean
    public Docket adminApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("iotCenter")
                .apiInfo(adminApiInfo())
                .enable(enable)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jiezhuo"))
                .paths(Predicates.and(PathSelectors.regex("/.*")))
                .build().securitySchemes(securitySchemes());

    }
    private List<ApiKey> securitySchemes(){
        //设置请求头信息
        List<ApiKey> result = new ArrayList<ApiKey>();
        ApiKey apiKey = new ApiKey("Authorization","token","header");
        result.add(apiKey);
        return result;
    }
    private ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .title("教育平台")
                .description("本文档描述了后台中心教育平台接口定义")
//                .termsOfServiceUrl("doc.html")
                .version("1.0")
                .contact(new Contact("java", "http://jz.com", "1123@qq.com"))
                .build();
    }
}
